package com.grgbanking.encryp.dao;
import com.grgbanking.encryp.bean.KeyInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import javax.transaction.Transactional;

@Repository
public interface UserRepository extends JpaRepository<KeyInfo, Long>{

    //默认提供了Optional<User> findById(Long id);

    KeyInfo findByName(String name);

    @Query("select u from KeyInfo u where u.id <= ?1")
    Page<KeyInfo> findMore(Long maxId, Pageable pageable);

    @Modifying
    @Transactional
    @Query("update KeyInfo u set u.name = ?1 where u.id = ?2")
    int updateById(String name, Long id);

    @Modifying
    @Transactional
    @Query("delete from KeyInfo u where u.name = ?1")
    int deleteByName(String keySN);

    @Modifying
    @Transactional
    @Query("update KeyInfo u set u.deleteflag =?2 where u.name = ?1")
    void updateDeletingByName(String keySN,String delete);

}